﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ShoppingCar.aspx.cs" Inherits="Maticsoft.Web.ShoppingCar" %>

<%@ Register src="Header2.ascx" tagname="Header2" tagprefix="uc1" %>
<%@ Register src="footer.ascx" tagname="footer" tagprefix="uc2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>购物车</title>
    <link rel="stylesheet" href="css/reset.css" />
    <link rel="stylesheet" href="css/common.css" />
    <script type="text/javascript" src="js/jquery.1.4.2-min.js"></script>
    <script type="text/javascript">
        function Settlement() {
            if ($("#productitem :checked").length > 0) {
                var ids = "";
                $("#productitem :checked").each(function () {
                    if (ids != "") {
                        ids += ",";
                    }
                    ids += $(this).attr("id");
                })
                window.location.href = "Settlement.aspx?ids=" + ids;
            }
            else {
                alert("请选择商品");
            }
        }

        function AddNum(id,i) {
            $.ajax({
                type: "get",
                url: "ProductDetail.aspx",
                data: "ope=addnum&productId=" + id + "&num=" + i + "&d=" + new Date().toString(),
                success: function (data) {
                    if (data == "1") {
                        alert("操作成功");
                        window.location.href = "ShoppingCar.aspx";
                    }
                    else if (data == "-1") {
                        alert("产品已下架");
                    }
                    else if (data == "-2") {
                        alert("库存不足");
                    }
                    else if (data == "-3") {
                        alert("超出购物限额");
                    }
                    else if (data == "-4") {
                        alert("超出购买限额");
                    }
                    else if (data == "-5") {
                        alert("请先登录");
                    }
                    else {
                        alert("添加失败");
                    }
                },
                error: function () {

                }
            })
        }

        function SelAllUp() {
            if ($("#SelAll1").attr("checked")) {
                $(".row :checkbox").attr("checked", "checked");
                $("#SelAll1").attr("checked", "checked");
                $("#SelAll2").attr("checked", "checked");
            }
            else {
                $(".row :checkbox").attr("checked", false);
                $("#SelAll1").attr("checked", false);
                $("#SelAll2").attr("checked", false);
            }
        }

        function SelAllDown() {
            if ($("#SelAll2").attr("checked")) {
                $(".row :checkbox").attr("checked", "checked");
                $("#SelAll1").attr("checked", "checked");
                $("#SelAll2").attr("checked", "checked");
            }
            else {
                $(".row :checkbox").attr("checked", false);
                $("#SelAll1").attr("checked", false);
                $("#SelAll2").attr("checked", false);
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <uc1:Header2 ID="Header1" runat="server" />
    <div class="row bg-white">
			<div class="safe_width">
				<div class="shop-cat-tit">
					<p>全部商品</p>
				</div>
				<div class="row" style="padding:20px 20px 30px 20px;line-height: 24px;">
					<div class="equal-2 fs-12 tc-black fl tl" style="width:47%">
						<p class="equal-1 fl mgr10">
							<input type="checkbox" id="SelAll1" onclick="SelAllUp();" /> 全选
						</p>
						<p class="equal-3 fl">商品信息</p>
					</div>
					<div class="equal-2 fl">
						<div class="equal-1 fs-12 tc-black fl tc">价格</div>
						<div class="equal-1 fs-12 tc-black fl tc">数量</div>
						<div class="equal-1 fs-12 tc-black fl tc">小计</div>
						<div class="equal-1 fs-12 tc-black fl tc" style="width:21%">操作</div>
					</div>
				</div>
				<div class="borderbox" id="productitem">
                    <asp:Repeater ID="Repeater1" runat="server">
                    <ItemTemplate>
                    <div class="row shop-car-indent">
						<div class="equal-2 fl">
							<p class="fl">
								<input type="checkbox" id="<%#Eval("ProductId") %>"> <img class="borderbox" src="uploadpic/<%#Eval("pic") %>" width="80" height="80" alt="">
							</p>
							<div class="equal-2 fl tc-black pad-10"><p><a href="ProductDetail.aspx?cid=<%#Eval("CategoryId") %>&id=<%#Eval("ProductId") %>" target="_blank" style="color:#333333"><%#Eval("ProductName") %></a></p></div>
							<div class="equal-1 fl tc-gray pad-10-0 tc" style="text-align:left"><p>规格：<%#Eval("ProductDesc")%></p><%#Maticsoft.Common.DigitHelper.GetInt32(Eval("Weight")) > 0 ? "<p>重量：" + Eval("Weight") + "克</p>" : ""%></div>
						</div>
						<div class="equal-2 fl">
							<div class="equal-1 tc-black fl tc line-hei-80 fb"><%#Eval("SalePrice")%></div>
							<div class="equal-1 tc-black fl tc">
								<p class="des-no">
									<button class="btn minus" type="button" onclick="AddNum(<%#Eval("ProductId") %>,-1)">-</button>
									<input type="text" value="<%#Eval("ProductNum") %>" class="number">
									<button class="btn plus" type="button" onclick="AddNum(<%#Eval("ProductId") %>,1)">+</button>
								</p>
							</div>
							<div class="equal-1 tc-black fl tc line-hei-80 fb tc-red"><%#(decimal.Parse(Eval("SalePrice").ToString()) * int.Parse(Eval("ProductNum").ToString())).ToString("f2")%></div>
							<div class="equal-1 tc-black fl tc line-hei-80" onclick="AddNum('<%#Eval("ProductId") %>',-<%#Eval("ProductNum") %>);" style="cursor:pointer">删除</div>
						</div>
					</div>
                    </ItemTemplate>
                    </asp:Repeater>
                    
				</div>
				<div class="borderbox buybtnbox">
					<div class="equal-2 fs-12 tc-black fl tl">
						<p class="equal-1 fl mgr10">
							<input type="checkbox" id="SelAll2" onclick="SelAllDown();" /> 全选
						</p>
						<p class="equal-3 fl">删除选中的商品 </p>
					</div>
					<div class="equal-2 fl">
						<div class=" fr tc">
							<button type="button" onclick="Settlement();">去结算</button>
						</div>
						<div class="fs-12 tc-black fr tr">已选商品<span class="fs-16 tc-red" runat="server" id="productNum">0 </span>件      合计（不含运费）：<span class="fs-20 tc-red" runat="server" id="totalMoney">￥0.00</span></div>
					</div>
				</div>

			</div>
		</div>
    <uc2:footer ID="footer1" runat="server" />
    </form>
    
</body>
</html>
<script language="javascript" type="text/javascript">
    //说明 所有的元素以ul li ul li ul li的循环格式
    $(document).ready(function () {
        $(".tab-nav ul li").children("ul").hide();
        $(".tab-nav").find("li:has(ul)").children("a").click(function () {
            if ($(this).next("ul").is(":hidden")) {
                $(this).next("ul").slideDown("fast");
                if ($(this).parent("li").siblings("li").children("ul").is(":visible")) {
                    $(this).parent("li").find("ul").hide();
                    $(this).parent("li").siblings("li").find("ul").slideUp("fast");
                    $(this).parent("li").siblings("li:has(ul)").children("a").css()
							.end().find("li:has(ul)").children("a").css();
                }
                return false;
            } else {
                $(this).children("input").prop("checked", false);
                $(this).next("ul").children("li").find("a").prop("checked", false);
                $(this).next("ul").slideUp("fast");
                $(this).next("ul").children("li").find("ul").fadeOut("fast");
                return false;
            }
        });
    });
	</script>
